﻿using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Lawn.AppServer
{
    public class MqService:IHostedService
    {

        private ILogger<MqService> logger;
        private IServerMq serverMq;
        public MqService(ILogger<MqService> _logger,IServerMq _serverMq)
        {
            this.logger = _logger;
            this.serverMq = _serverMq;
        }
        
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            await serverMq.Start().ConfigureAwait(false);
            logger.LogInformation("start..");
            await Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        { 
            logger.LogInformation("stop..");
            serverMq.Stop().ConfigureAwait(false);
            logger.LogInformation("stoped..");
            return Task.CompletedTask;
        }
    }
}